package com.dream.controller;

import com.dream.bean.User;
import com.dream.service.HelloService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * @author 匠人码农
 * @date 2020/12/05 16:47
 * 概要：
 *     疏通SSM
 *     请求url:http://localhost:8080/BookShop_SpringMVC/hello?id=1
 *     响应页面:
 *
 *
 */
@Controller
public class HelloController {

    @Autowired
    HelloService helloService;

    @RequestMapping("hello")
    public String hello(@RequestParam(value="id") String idStr,Model model){

        Integer id = Integer.valueOf(idStr);

        //返回的画面是视图解析器配置的前缀（/pages/）+ hello + 后缀（.jsp） 即/pages/hello.jsp
        User user = helloService.queryUser(id);

        model.addAttribute("user",user);

        return "hello";
    }
}
